package U4;

import java.util.HashMap;
import java.util.Map;

public class Test2 {
	public int[] twoSum1 (int[] numbers, int target) {
        for(int i = 0;i < numbers.length; ++ i) {
        	for(int j = i + 1;j < numbers.length;j ++) {
        		if(numbers[j] == target - numbers[i]) {
        			return new int[] {i,j};
        		}
        	}
        }
        return null;
    }
	public int[] twoSum2 (int[] numbers, int target) {
		   Map<Integer, Integer> map = new HashMap<>();
	        for (int i = 0; i < numbers.length; i++) {
	            map.put(numbers[i], i);
	        }
	        for (int i = 0; i < numbers.length; i++) {
	            int temp = target - numbers[i];
	            if (map.containsKey(temp) && map.get(temp) != i) {
	                return new int[] { i, map.get(temp) };
	            }
	        }
	        return null;

    }

}
